Skip to main content
OpenCLIP provides flexible image preprocessing with automatic configuration based on model requirements and customizable augmentation strategies.

Quick Start

Preprocessing is automatically configured when loading models:

Preprocessing Configuration

PreprocessCfg

The PreprocessCfg dataclass defines all preprocessing parameters:
int | Tuple[int, int]
default:"224"
Target image size. Can be int for square images or (height, width) tuple.
Tuple[float, float, float]
RGB mean values for normalization. Defaults to OpenAI CLIP values: (0.48145466, 0.4578275, 0.40821073)
Tuple[float, float, float]
RGB standard deviation for normalization. Defaults to: (0.26862954, 0.26130258, 0.27577711)
str
default:"bicubic"
Resize interpolation method: ‘bicubic’, ‘bilinear’, or ‘nearest’
str
default:"shortest"
Resize strategy:
  • 'shortest': Resize shortest edge, then center crop
  • 'longest': Resize longest edge, then center crop/pad
  • 'squash': Direct resize to target size (may distort)

Creating Transforms

image_transform_v2()

Create preprocessing transforms from configuration:

Resize Modes

Shortest Edge (Default)

Resize shortest edge to target, then center crop:
This is the default for most CLIP models and preserves aspect ratio before cropping.

Longest Edge

Resize longest edge, pad to square:
Useful when preserving all image content is important.

Squash Mode

Direct resize (may distort aspect ratio):
Used by SigLIP models and some other architectures.

Augmentation Configuration

AugmentationCfg

Configure training data augmentation:
Tuple[float, float]
default:"(0.9, 1.0)"
Scale range for RandomResizedCrop. Values are fractions of original image size.
Tuple[float, float]
Aspect ratio range for RandomResizedCrop
Tuple[float, ...]
Color jitter parameters: (brightness, contrast, saturation, hue)
float
Probability of applying color jitter (0.0 to 1.0)
float
Probability of converting to grayscale (0.0 to 1.0)
bool
default:"False"
Use timm library’s augmentation (RandAugment, etc.)

Example Augmentation Configs

Normalization

Standard Normalization Values

Different model families use different normalization:
Using incorrect normalization values will significantly degrade model performance. Always use the values the model was trained with.

Custom Preprocessing

Override Model Defaults

Manual Transform Pipeline

Advanced Features

Non-Square Images

Some models support non-square inputs:

Multiple Resolutions

Use different resolutions at inference:

Batch Preprocessing

Complete Example